package com.neusoft.neu24.service.impl;

import com.neusoft.neu24.Result.CommonResult;
import com.neusoft.neu24.entity.Role;
import com.neusoft.neu24.mapper.RoleMapper;
import com.neusoft.neu24.service.IRoleService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService {

    @Resource
    private RoleMapper roleMapper;


    @Override
    public CommonResult<List<Role>> listAll() {
        return CommonResult.success(roleMapper.listAll());
    }

    @Override
    public CommonResult<Integer> add(Role role) {
        int i = roleMapper.add(role);
        return CommonResult.success(role.getId());
    }

    @Override
    public CommonResult<Integer> editById(Role role) {
        return CommonResult.success(roleMapper.edit(role));
    }

    @Override
    public CommonResult<Integer> deleteById(Role role) {
        return CommonResult.success(roleMapper.deleteRoleById(role.getId()));
    }

    @Override
    public CommonResult<List<Integer>> loadById(Integer rid) {
        return CommonResult.success(roleMapper.loadById(rid));
    }

    @Override
    public CommonResult<List<Integer>> authEditById(Integer rid, List<Integer> sids) {
        roleMapper.authDeleteById(rid);
        if(!sids.isEmpty()) roleMapper.authInsertById(rid, sids);
        return null;
    }


}
